package cj.web.marriage.controllers;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.utils.DateUtils;
import cj.web.activity.constants.SCOrderStatusEnum;
import cj.web.activity.domain.SCOrder;
import cj.web.admin.constants.MemuEnum;
import cj.web.marriage.constants.MarriageSCOrderStatusEnum;
import cj.web.marriage.dao.MarriageSCOrderDAO;

@Path("/marriagescorder")
public class MarriageSCOrderController {

private static Logger logger = Logger.getLogger(MarriageSCOrderController.class.getName());
	
	@Autowired
	private MarriageSCOrderDAO scOrderDAO;
	
	@Get("show")
	public String show(Model model) {
	
		// EnumSet的使用
        EnumSet<MarriageSCOrderStatusEnum> scOrderStatusEnum = EnumSet.allOf(MarriageSCOrderStatusEnum.class);
        
		//MemuEnum
        model.add("MemuEnum",MemuEnum.marriagescorder);
        model.add("scOrderStatusEnum",scOrderStatusEnum);
		return "/views/activity/sc/scOrderList.vm";
	}
	
	@Post("getList")
	public String queryList(SCOrder scOrder) {
	
		JSONObject jo = new JSONObject();
		List<Map> objs = scOrderDAO.query(scOrder);
		
		for(Map obj:objs)
		{
			obj.put("createAt", DateUtils.getMinusTime(obj.get("createAt").toString(), DateUtils.DATE_FULL_STR, 0));
			obj.put("updateAt", DateUtils.getMinusTime(obj.get("updateAt").toString(), DateUtils.DATE_FULL_STR, 0));
		}
		
		int size = scOrderDAO.queryszie(scOrder);
		
		jo.put("data", objs);
		jo.put("draw", scOrder.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@"+jo.toString();
	}
	
	@Get("updateStatus")
	public String updateStatusById(@Param("id") int id){
		SCOrder obj = scOrderDAO.queryById(id);
		if(obj!=null){
			obj.setSource("SYS");
			obj.setStatus(SCOrderStatusEnum.YXF.getValue());
			scOrderDAO.updateStatusByOrderNo(obj);
		}		
		return "r:show";
	}
}
